package com.example.controller;

import com.example.common.Result;
import com.example.entity.ProductInfo;
import com.example.service.ProductInfoService;
import com.example.vo.ProductInfoVO;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/productInfo")
public class ProductInfoController {
    @Resource
    private ProductInfoService productInfoService;

    @PutMapping("/add")
    public Result insert(@RequestBody ProductInfo productInfo){
        productInfoService.insert(productInfo);
        return Result.success();
    }

    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        productInfoService.remove(id);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody ProductInfo productInfo) {
        productInfoService.update(productInfo);
        return Result.success();
    }

    @GetMapping("/page")
    public Result getList(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageInfo<ProductInfo> list = productInfoService.getProductInfoList(pageNum, pageSize);
        return Result.success(list);
    }

    @PostMapping("/search")
    public Result search(@RequestBody ProductInfoVO productInfoVO) {
        PageInfo<ProductInfo> list = productInfoService.getProductInfoListByCondition(productInfoVO.getPageNum(), productInfoVO.getPageSize(), productInfoVO.getSuper());
        return Result.success(list);
    }
}
